package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.bean.Employee;
import com.itheima.common.PageParm;
import com.itheima.dao.EmployeeDao;
import com.itheima.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    private EmployeeDao em;


    @Override
    public Employee login(Employee employee) {
        LambdaQueryWrapper<Employee> qw = new LambdaQueryWrapper<>();
        qw.eq(Employee::getUsername,employee.getUsername()).eq(Employee::getPassword,employee.getPassword());

        Employee employee1 = em.selectOne(qw);
        return employee1;


    }

    @Override
    public int add(Employee employee) {
        int insert = em.insert(employee);
        return insert;
    }

    @Override
    public IPage<Employee> selectPage(PageParm page) {
        IPage<Employee> page1 = new Page<>(page.getPage(), page.getPageSize());
        LambdaQueryWrapper<Employee> qw = new LambdaQueryWrapper<>();
        qw.like(page.getName()!=null,Employee::getName,page.getName());
        IPage<Employee> employeeIPage = em.selectPage(page1, qw);
        return employeeIPage;


    }

    @Override
    public int update(Employee employee) {




        return  em.updateById(employee);

    }
}
